<?php
/**
 * Created by PhpStorm.
 * User: ttl
 * Date: 2019/5/25
 * Time: 16:01
 */

namespace app\admin\controller;

use think\AjaxPage;
use think\Db;
use think\Variable;
class User extends Base
{
    public function user_index(){
        return $this->fetch();
    }

    public function ajax_user(){

        $where = []; // 搜索条件
        $key_word = input('key_word/s', '');
        if ($key_word) {
            $where['nickname'] = ['like', '%' . $key_word . '%'];
        }

        $count = M('User')->where($where)->count();
        $Page = new AjaxPage($count, 20);

        $show = $Page->show();
        $orderby1 = input('orderby1/s', '');
        $orderby2 = input('orderby2/s', '');

        $order_str = "$orderby1 $orderby2";
        $users = M('User')->where($where)->order($order_str)->limit($Page->firstRow . ',' . $Page->listRows)->select();

        $this->assign('users', $users);
        $this->assign('page', $show);// 赋值分页输出
        return $this->fetch();
    }
}